# -*- coding: utf-8 -*-
"""
Created on Thu Jun 10 16:19:03 2021
rainflow('w')
@author: Allen
"""

import pandas as pd
import numpy as np
from math import sin,cos

data = pd.read_excel('rainflowdata.xlsx')
#输出数据属性1
print(data.shape)

#rainflow
processed = {}
time = []
signal = []
l1 = []
l2 = []
l3 = []
l4 = []
l5 = []
time = data['Time [s]']
signal = data['Maximum [MPa]']

import rainflow
for rng, mean, count, i_start, i_end in rainflow.extract_cycles(signal):
	l1.append(rng)
	l2.append(mean)
	l3.append(count)
	l4.append(i_start)
	l5.append(i_end)

processed['rng'] = l1
processed['mean'] = l2
processed['count'] = l3
processed['i_start'] = l4
processed['i_end'] = l5
#创建数据框架
pcd_data = pd.DataFrame(processed)

# sort data
srt_data = pcd_data.sort_values(by='mean')

# output
srt_data.to_excel('processedData.xlsx')
